<template>
  <div class="index">
    <!-- 头部 -->
    <header>
      <div @click="goToCity" class="city">
        健康 · <span class="cityName">{{loCityName}}</span>
      </div>
      <van-search v-model="value" placeholder="请输入搜索关键词" />
      <van-badge :content="5">
        <span class="iconfont icon-lingdang"></span>
      </van-badge>
    </header>
    <!-- 分类 -->
    <van-grid :border="false" :column-num="3" class="classify">
      <van-grid-item
        v-for="item in classify"
        :key="item.id"
        @click="goTo(item.url)"
      >
        <img :src="item.img" alt="" />
        <p class="title">{{ item.title }}</p>
        <p>{{ item.msg }}</p>
      </van-grid-item>
    </van-grid>
    <!-- 导航 -->
    <van-grid :border="false" :column-num="5" class="nav">
      <van-grid-item v-for="item in nav" :key="item.id" @click="goTo(item.url)">
        <img :src="item.img" alt="" />
        <p>{{ item.title }}</p>
      </van-grid-item>
    </van-grid>
    <!-- banner -->
    <div class="banner">
      <img src="http://qvxb53t4o.hd-bkt.clouddn.com/index/banner1.png" alt="" />
      <img src="http://qvxb53t4o.hd-bkt.clouddn.com/index/banner2.png" alt="" />
    </div>
    <!-- 医院 -->
    <div class="hospital">
      <img
        src="http://qvxb53t4o.hd-bkt.clouddn.com/index/hospital.png"
        alt=""
      />
    </div>
    <!-- 医生 -->
    <div class="doctor">
      <p class="title">
        <span>我的医生</span>
        找一找我看过的医生，关注Ta
      </p>
      <div class="doctor-con">
        <div v-for="item in doctor" :key="item.id">
          <div class="top">
            <img :src="item.img" alt="" />
            <div class="content">
              <p>
                <span class="name">{{ item.name }}</span>
                <span>{{ item.position }}</span>
              </p>
              <p>{{ item.education }} {{ item.office }}</p>
            </div>
            <img
              src="../../assets/index/images/doctor-icon.png"
              alt=""
              class="icon"
            />
          </div>
          <div class="bottom">
            <div class="good-job">
              <van-icon name="good-job" />
              本地名医
            </div>
            <div class="feature">{{ item.feature }}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 专科服务 -->
    <div class="service">
      <p class="title">
        专科服务<span
          >以服务<span>30792929</span>人 <span>98.5%</span>满意</span
        >
      </p>
      <div class="service-nav">
        <div v-for="item in serviceNav" :key="item.id">
          <img :src="item.img" alt="" />
          <p>{{ item.title }}</p>
        </div>
      </div>
      <div class="serviceCon serviceConTop">
        <div
          v-for="item in serviceConTop"
          :key="item.id"
          :style="'background-image:url(' + item.bgImg + ')'"
        >
          <p class="conTitle">{{ item.title }}</p>
          <p class="conMsg topMsg" :style="'background-color:' + item.bgColor">
            {{ item.msg }}
          </p>
        </div>
      </div>
      <div class="serviceCon serviceConBottom">
        <div
          v-for="item in serviceConBottom"
          :key="item.id"
          :style="'background-image:url(' + item.bgImg + ')'"
        >
          <p class="conTitle">{{ item.title }}</p>
          <p class="conMsg">{{ item.msg }}</p>
        </div>
      </div>
    </div>
    <!-- 微脉精选 -->
    <div class="choiceness">
      <p class="title">
        <span>微脉精选</span>
        <span>更多></span>
      </p>
      <div class="choiceness-con">
        <div v-for="item in choiceness" :key="item.id">
          <img :src="item.img" alt="" />
          <p class="title">{{ item.title }}</p>
          <p class="price">￥{{ item.price }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";

import { getIndex } from "../../utils/api";

export default {
  setup() {
    const router = useRouter();

    const value = ref("");

    const classify = ref([
      {
        id: 1,
        title: "去挂号",
        msg: "专家预约",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/classify-registration.png",
        url: "/registration",
      },
      {
        id: 2,
        title: "问专家",
        msg: "线上门诊",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/classify-expert.png",
        url: "/expert",
      },
      {
        id: 3,
        title: "专科频道",
        msg: "特色专区",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/classify-channel.png",
        url: "/specialized",
      },
    ]);

    const nav = ref([
      {
        id: 1,
        title: "1元义诊",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/nav-seedoctor.png",
        url: "/home/diagnosis",
      },
      {
        id: 2,
        title: "在家购药",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/nav-buymedicine.png",
        url: "/buymedicine",
      },
      {
        id: 3,
        title: "名医诊室",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/nav-famousdoctors.png",
        url: "/home/consultation",
      },
      {
        id: 4,
        title: "极速咨询",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/nav-consult.png",
        url: "/consult",
      },
      {
        id: 5,
        title: "疫苗预约",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/nav-vaccine.png",
        url: "",
      },
    ]);

    const goTo = (url) => {
      router.push(url);
    };

    const doctor = ref([]);

    const getDoctor = async () => {
      const res = await getIndex();
      doctor.value = res.result[0].mydoctor;
    };

    onMounted(() => {
      getDoctor();
    });

    const serviceNav = ref([
      {
        id: 1,
        title: "男科义诊",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service1.png",
      },
      {
        id: 2,
        title: "中医义诊",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service2.png",
      },
      {
        id: 3,
        title: "内科",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service3.png",
      },
      {
        id: 4,
        title: "0元护肤",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service4.png",
      },
      {
        id: 5,
        title: "消化科",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service5.png",
      },
      {
        id: 6,
        title: "孕产专科",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service6.png",
      },
      {
        id: 7,
        title: "妇科健康",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service7.png",
      },
      {
        id: 8,
        title: "宝宝健康",
        img: "http://qvxb53t4o.hd-bkt.clouddn.com/index/service8.png",
      },
    ]);

    const serviceConTop = ref([
      {
        id: 1,
        title: "治阳痿补肾专区",
        msg: "低价抢男性好药",
        bgImg: "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConTop1.png",
        bgColor: "#7dc8a3",
      },
      {
        id: 2,
        title: "妇科免费咨询",
        msg: "大牌好药抢购",
        bgImg: "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConTop2.png",
        bgColor: "#e95273",
      },
    ]);

    const serviceConBottom = ref([
      {
        id: 1,
        title: "国医团队",
        msg: "孙泰和妇科圣手",
        bgImg:
          "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConBottom1.png",
      },
      {
        id: 2,
        title: "慢病购药专区",
        msg: "高血压高血脂",
        bgImg:
          "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConBottom2.png",
      },
      {
        id: 3,
        title: "改善亚健康",
        msg: "科学减脂 内分泌调理>",
        bgImg:
          "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConBottom3.png",
      },
      {
        id: 4,
        title: "妈咪好孕",
        msg: "孕产一站式服务",
        bgImg:
          "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConBottom4.png",
      },
      {
        id: 5,
        title: "医护上门",
        msg: "在线预约医护到家",
        bgImg:
          "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConBottom5.png",
      },
      {
        id: 6,
        title: "女性关爱",
        msg: "守护女性健康",
        bgImg:
          "http://qvxb53t4o.hd-bkt.clouddn.com/index/serviceConBottom6.png",
      },
    ]);

    const choiceness = ref([]);

    const getChoiceness = async () => {
      const res = await getIndex();
      choiceness.value = res.result[0].wmjx;
    };
    // 首页城市跳转和取本地存储city
    const goToCity = () => {
      router.push("/home/city");
    };
    const getCityName = async () => {
      let loCityName = localStorage.getItem("city") || "杭州";
      let cityNmae = document.querySelector(".cityName");
      cityNmae.innerHTML = loCityName;
    };

    onMounted(() => {
      getChoiceness();
      getCityName();
    });

    return {
      goToCity,
      value,
      classify,
      nav,
      goTo,
      doctor,
      getDoctor,
      serviceNav,
      serviceConTop,
      serviceConBottom,
      choiceness,
      getChoiceness,
      getCityName,
    };
  },
};
</script>

<style lang="less" scoped>
.index {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 56px;
  overflow: auto;

  header {
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 19px;
  }
  .classify {
    > div {
      font-size: 12px;

      .title {
        font-size: 17px;
        font-weight: 700;
        color: #000;
      }

      p {
        margin: 5px 0;
        color: #999999;
      }

      img {
        width: 39px;
        height: 39px;
      }
    }
  }
  .nav {
    img {
      width: 45px;
      height: 45px;
    }

    p {
      font-size: 13px;
      color: #999999;
    }
  }
  .banner {
    img {
      width: 100%;
      margin-top: 5px;
    }
  }
  .hospital {
    img {
      width: 345px;
      height: 160px;
      display: block;
      margin: 0 auto;
    }
  }
  .doctor {
    .title {
      font-size: 14px;
      color: #999ea7;
      padding: 0 20px;

      span {
        font-size: 20px;
        font-weight: 700;
        color: #000;
      }
    }

    .doctor-con {
      margin: 32px 0;
      overflow: auto;
      height: 100px;
      display: flex;

      > div {
        width: 300px;
        height: 100x;
        flex-shrink: 0;
      }

      .top {
        display: flex;
        align-items: center;
        position: relative;

        img {
          width: 45px;
          height: 45px;
          margin: 0 5px;
        }

        p {
          font-size: 13px;
          color: #6f7277;
          line-height: 13px;

          .name {
            font-size: 18px;
            color: #333333;
            margin-right: 12px;
          }
        }

        .icon {
          width: 18px;
          height: 18px;
          position: absolute;
          right: 0;
          top: 0;
        }
      }

      .bottom {
        display: flex;
        align-items: center;
        padding: 0 10px;

        .good-job {
          width: 65px;
          height: 18px;
          background-color: #e58133;
          border-radius: 9px;
          font-size: 11px;
          color: #fff;
          display: flex;
          justify-content: center;
          align-items: center;
          margin-left: 20px;
          padding: 0 5px;
        }

        .feature {
          margin-left: 10px;
          font-size: 12px;
          color: #e1b78e;
        }
      }
    }
  }
  .service {
    .title {
      font-size: 20px;
      color: #333333;
      font-weight: 700;
      padding: 0 20px;

      > span {
        font-size: 10px;
        margin-left: 14px;
        font-weight: normal;

        > span {
          color: #e58133;
        }
      }
    }

    .service-nav {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-evenly;

      > div {
        width: 21%;
        height: 80px;
        text-align: center;
        margin-bottom: 40px;

        img {
          width: 44px;
          height: 44px;
        }

        p {
          font-size: 14px;
          color: #333333;
          line-height: 0;
        }
      }
    }

    .serviceCon {
      display: flex;
      justify-content: space-evenly;
      flex-wrap: wrap;

      > div {
        background-size: 100% 100%;
      }
    }

    .serviceConTop {
      > div {
        width: 180px;
        height: 86px;
        box-sizing: border-box;
        padding-left: 15px;
        position: relative;
      }
    }

    .serviceConBottom {
      text-align: center;

      > div {
        width: 115px;
        height: 151px;
        margin-top: 8px;
      }
    }

    .conTitle {
      font-size: 16px;
      font-weight: 600;
    }

    .conMsg {
      font-size: 12px;
      color: #6f7277;
      line-height: 0;
    }

    .topMsg {
      height: 24px;
      line-height: 24px;
      color: #fff;
      border-radius: 10px;
      position: absolute;
      z-index: 99;
      top: 30px;
      padding: 0 5px;
    }
  }
  .choiceness {
    .title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 20px;

      :nth-child(1) {
        font-size: 20px;
        font-weight: 700;
        color: #000;
      }

      :nth-child(2) {
        font-size: 14px;
        color: #999ea7;
      }
    }

    .choiceness-con {
      height: 190px;
      display: flex;
      overflow: auto;

      > div {
        flex-shrink: 0;
        margin-left: 20px;

        img {
          width: 105px;
          height: 109px;
        }

        :nth-child(2) {
          font-size: 12px;
          color: #525252;
          width: 105px;
          padding: 0;
        }

        :nth-child(3) {
          font-size: 9px;
          color: #de7570;
        }
      }
    }
  }
  .city {
    width: 100px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 16px;
  }
}
</style>
